home *** CD-ROM | disk | FTP | other *** search
/ Programming Sound Cards / Programming Sound Cards.iso / sound_80 / playinfo.pas < prev    next >
Pascal/Delphi Source File  |  1995-01-01  |  5KB  |  227 lines

  1. unit PlayInfo;
  2. {
  3.   Routines shared by all the Play objects. These are things
  4.   that everyone can do, or at least that can be done on more
  5.   than one device.
  6.  
  7.   Status: Beta
  8.   Date: 5/16/93
  9.  
  10.   Copyright (c) June 1993, by Charlie Calvert
  11.   Feel free to use this code as an adjunct to your own programs.
  12. }
  13.  
  14. interface
  15. uses
  16.   Strings,
  17.   MMSystem,
  18.   WinProcs,
  19.   WinTypes;
  20.  
  21. const
  22.   MsgLen = 200;
  23.  
  24. var
  25.   wDeviceID: Word;
  26.   PlayWindow: HWnd;
  27.  
  28. function CloseMCI: Boolean; export;
  29. function ErrorMsg(Error: LongInt; Msg: PChar): Boolean; export;
  30. function GetDeviceID: Word; export;
  31. function GetInfo(S: PChar): PChar; export;
  32. function GetLen: Longint; export;
  33. function GetLocation: LongInt; export;
  34. function GetMode: Longint; export;
  35. function OpenMCI(PWindow: HWnd; FileName, DeviceType: PChar): Boolean; export;
  36. function PlayMCI: Boolean; export;
  37. function SetTimeFormatMs: Boolean; export;
  38. function StopMci: Boolean; export;
  39.  
  40. implementation
  41.  
  42. function CloseMci: Boolean;
  43. var
  44.   Result: LongInt;
  45.   S1: array[0..MsgLen] of Char;
  46. begin
  47.   CloseMci := True;
  48.   Result := mciSendCommand(wDeviceID, MCI_Close, 0, 0);
  49.   if Result <> 0 then begin
  50.     CloseMci := False;
  51.     ErrorMsg(Result, S1);
  52.     exit;
  53.   end;
  54.   wDeviceID := 0;
  55. end;
  56.  
  57. function GetDeviceId: Word;
  58. begin
  59.   GetDeviceId := wDeviceId;
  60. end;
  61.  
  62. function GetErrorMessage(RC:LongInt; S: PChar): PChar;
  63. begin
  64.   if not mciGetErrorString(RC, S, MsgLen) then
  65.     StrCopy(S, 'No message available');
  66.   GetErrorMessage := S;
  67. end;
  68.  
  69. function ErrorMsg(Error: LongInt; Msg: PChar): Boolean;
  70. var
  71.   S, S1: array[0..MsgLen] of Char;
  72. begin
  73.   ErrorMsg := True;
  74.   StrCopy(S, 'Return Code: ');
  75.   Str(Error:5, S1);
  76.   StrCat(S, S1);
  77.   StrCat(S, Msg);
  78.   StrCat(S, GetErrorMessage(Error, S1));
  79.   if Error <> 0 then begin
  80.     MessageBox(0, S1, 'Information', mb_OK);
  81.     ErrorMsg := False;
  82.   end;
  83. end;
  84.  
  85. function GetInfo(S: PChar): PChar;
  86. var
  87.   Info: TMci_Info_Parms;
  88.   Flags: LongInt;
  89.   S1: array[0..MsgLen] of Char;
  90.   Result: LongInt;
  91. begin
  92.   Info.dwCallBack := 0;
  93.   Info.lpstrReturn := S;
  94.   Info.dwRetSize := MsgLen;
  95.   Flags := Mci_Info_Product;
  96.   Result := mciSendCommand(wDeviceID, Mci_Info, Flags, LongInt(@Info));
  97.   ErrorMsg(Result, S1);
  98.   GetInfo := S;
  99. end;
  100.  
  101. function GetLen: Longint;
  102. var
  103.   Info: TMci_Status_Parms;
  104.   Flags,
  105.   Result: LongInt;
  106.   S1: array [0..MsgLen] of Char;
  107. begin
  108.   FillChar(Info, SizeOf(TMci_Status_Parms), 0);
  109.   Info.dwItem := Mci_Status_Length;
  110.   Flags := Mci_Status_Item;
  111.   Result := MciSendCommand(wDeviceID, Mci_Status, Flags, LongInt(@Info));
  112.   if Result <> 0 then begin
  113.     ErrorMsg(Result, S1);
  114.     exit;
  115.   end;
  116.   GetLen := Info.dwReturn;
  117. end;
  118.  
  119. function GetLocation: LongInt;
  120. var
  121.   Info: TMci_Status_Parms;
  122.   Flags: LongInt;
  123.   Result: LongInt;
  124.   S: array[0..MsgLen] of Char;
  125.  
  126. begin
  127.   Info.dwItem := Mci_Status_Position;
  128.   Flags := Mci_Status_Item;
  129.   Result := MciSendCommand(wDeviceID, Mci_Status, Flags, LongInt(@Info));
  130.   if Result <> 0 then begin
  131.     ErrorMsg(Result, S);
  132.     Exit;
  133.   end;
  134.   GetLocation := Info.dwReturn;
  135. end;
  136.  
  137. function GetMode: Longint;
  138. var
  139.   Info: TMci_Status_Parms;
  140.   Flags,
  141.   Result: LongInt;
  142.   S1: array [0..MsgLen] of Char;
  143. begin
  144.   FillChar(Info, SizeOf(TMci_Status_Parms), 0);
  145.   Info.dwItem := Mci_Status_Mode;
  146.   Flags := Mci_Status_Item;
  147.   Result := MciSendCommand(wDeviceID, Mci_Status, Flags, LongInt(@Info));
  148.   if Result <> 0 then begin
  149.     ErrorMsg(Result, S1);
  150.     exit;
  151.   end;
  152.   GetMode := Info.dwReturn;
  153. end;
  154.  
  155. function OpenMCI(PWindow: HWnd; FileName, DeviceType: PChar): Boolean;
  156. var
  157.   OpenParms: TMci_Open_Parms;
  158.   Style: LongInt;
  159.   Result: LongInt;
  160.   S1: array [0..MsgLen] of Char;
  161. begin
  162.   OpenMCI := True;
  163.   PlayWindow := PWindow;
  164.   OpenParms.lpstrDeviceType := DeviceType;
  165.   OpenParms.lpstrElementName := FileName;
  166.   Style := Mci_Open_Type or Mci_Open_Element;
  167.   Result := MciSendCommand(0, MCI_OPEN, Style, LongInt(@OpenParms));
  168.   if Result <> 0 then begin
  169.     OpenMCI := False;
  170.     ErrorMsg(Result, S1);
  171.     exit;
  172.   end;
  173.   wDeviceId := OpenParms.wDeviceID;
  174. end;
  175.  
  176. function PlayMCI: Boolean;
  177. var
  178.   Result: LongInt;
  179.   Info: TMci_Play_Parms;
  180.   S1: array[0..MsgLen] of Char;
  181. begin
  182.   PlayMci := True;
  183.   Info.dwCallBack := PlayWindow;
  184.   Result := MciSendCommand(wDeviceID, Mci_Play, Mci_Notify, LongInt(@Info));
  185.   if Result <> 0 then begin
  186.     PlayMci := False;
  187.     ErrorMsg(Result, S1);
  188.     exit;
  189.   end;
  190. end;
  191.  
  192. function SetTimeFormatMS: Boolean;
  193. var
  194.   Info: TMci_Set_Parms;
  195.   Flags,
  196.   Result: LongInt;
  197.   S1: array [0..MsgLen] of Char;
  198. begin
  199.   SetTimeFormatMS := True;
  200.   Info.dwTimeFormat := Mci_Format_Milliseconds;
  201.   Flags := Mci_Set_Time_Format;
  202.   Result := MciSendCommand(wDeviceID, MCI_Set, Flags, LongInt(@Info));
  203.   if Result <> 0 then begin
  204.     ErrorMsg(Result, S1);
  205.     SetTimeFormatMS := False;
  206.   end;
  207. end;
  208.  
  209. function StopMci: Boolean;
  210. var
  211.   Result: LongInt;
  212.   Info: TMci_Generic_Parms;
  213.   S1: array[0..MsgLen] of Char;
  214. begin
  215.   StopMci := True;
  216.   Info.dwCallBack := 0;
  217.   Result := MciSendCommand(wDeviceID, Mci_Stop, Mci_Notify, LongInt(@Info));
  218.   if Result <> 0 then begin
  219.     StopMci := False;
  220.     ErrorMsg(Result, S1);
  221.     exit;
  222.   end;
  223. end;
  224.  
  225. begin
  226.   wDeviceId := 0;
  227. end.